#pragma once

#include "BasicShapes.h"

#include "ShapeLibrary.h"
#include "TextureLibrary.h"
#include "ShaderPairLibrary.h"
#include "ModelLibrary.h"

#include "BasicReaderWriter.h"

// The tokens found in the wave front file
#define TOKEN_VERTEX "v"
#define TOKEN_TEXTURE_COORD "vt"
#define TOKEN_VERTEX_NORMAL "vn"
#define TOKEN_VECTOR_PARAMETER "vp"
#define TOKEN_COMMENT "#"

// The structure for holding the WaveFront index structure for
// defining a triangle.
struct WaveFrontTriangle
{
	int vertex1;
	int texture1;
	int normal1;

	int vertex2;
	int texture2;
	int normal2;

	int vertex3;
	int texture3;
	int normal3;


};


class WaveFrontObjLoader
{
public:
	WaveFrontObjLoader(ID3D11Device* device);

	void LoadWaveFrontShapes(const wchar_t objFilePath[], Shape*** shapes, int *numberOfShapes);

private:
	BasicShapes^ shapesMaker;
	ID3D11Device* device;
	BasicReaderWriter^ basicReaderWriter;

	void ProcessWaveFrontData(HANDLE file, Shape*** shapes, int *numberOfShapes);
	char* ReadNextToken(HANDLE file); 
	char* ReadToEndOfLineAndReadNextToken(HANDLE file);
	char* ReadToEndOfLine(HANDLE file);
	char* ReadListOfFloatsAndReadNextToken(HANDLE file, float **vectorOfFloats, int *totalNumberOfFloats);

	Shape* CreateNewShape(	char*	currentObjectName,
							List*	currentListOfVertices,
							List*	currentListOfNormals,
							List*	currentListOfTextureCoords,
							List*	currentListOfIndices);

	void ClearResources(List*	currentListOfVertices,
									List*	currentListOfNormals,
									List*	currentListOfTextureCoords,
									List*	currentListOfIndices);

	char* ReadListOfIndicesAndReadNextToken(HANDLE file, WaveFrontTriangle **triangle);
	void SplitTriangleComponents(char *indexDesc, int* v, int* t, int* n);

	bool IsLetter(char c);
	bool IsNumber(char c);
	bool IsSymbol(char c);
	bool IsHash(char c);
	bool IsEOFL(char c);
	bool IsFloat(char* str);

};

